package com.cy.study.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cy.study.common.Response;
import com.cy.study.req.AddCommentReq;
import com.cy.study.req.PageCommentReq;
import com.cy.study.res.PageCommentRes;
import com.cy.study.service.CommentService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 评论控制器
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/comment")
@CrossOrigin
public class CommentController {

    private final CommentService commentService;

    /**
     * 用户添加心得评论
     * @param req
     * @return
     */
    @PostMapping("/addComment")
    public Response<Integer> addComment(@RequestBody AddCommentReq req){
        Integer id = commentService.addComment(req);
        return Response.success(id);
    }

    /**
     * 心得评论查询
     * @param req
     * @return
     */
    @PostMapping("/pageComment")
    public Response<Page<PageCommentRes>> pageComment(@RequestBody PageCommentReq req){
        Page<PageCommentRes> res = commentService.pageComment(req);
        return Response.success(res);
    }

}
